

function say() {
    alert("LC:1574. 删除最短的子数组使剩余数组有序");
}
say();


//参考
//https://leetcode-cn.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/solution/java-jian-dan-on-by-avlgood2018/
/**
 * @param {number[]} arr
 * @return {number}
 */
var findLengthOfShortestSubarray = function(arr) {
    //10:30-45
    var left = 0, len = arr.length
    
    while(left < len - 1){
        if(arr[left] <= arr[left + 1]){
            left ++
        }else {
            break
        }
    }
    // left = len - 1 return 0
    if(left == len - 1){ return 0 }

    var right = len - 1
    while(right > 0){
        if(arr[right - 1] <= arr[right]){
            right --
        }else {
            break
        }
    }

    var res = Math.min(right, len - left - 1)

    var i = 0, j = right
    while(i <= left && j < len){ //???
        if(arr[i] <= arr[j]){
            res = Math.min(res, j - i - 1)
            console.log('循环',i,'j',j)
            i ++
        }else {
            j ++
        }
    }
    console.log('i',i,'j',j,'right',right,'left',left)

    return res
};
